<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>设备信息添加</title>
    <link rel="stylesheet" href="${basePath}/plugins/kitadmin/css/theme/default.css" id="theme">
    <link rel="stylesheet" href="${basePath}/plugins/kitadmin/css/kitadmin.css" id="kitadmin">
    <link rel="stylesheet" href="${basePath}/css/doc.css">
    <link rel="stylesheet" href="${basePath}/plugins/kitadmin/css/layui.css" id="layui">
</head>
<body>

<div class="kit-doc">
    <form class="layui-form layui-form-pane" action="">
    <#--设备型号-->
        <div class="layui-form-item">
            <label class="layui-form-label">设备型号：</label>
            <div class="layui-input-block">
                <input value="${device.deviceNo}" type="text" name="deviceNo" placeholder="请输入设备型号" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
    <#--设备名称-->
        <div class="layui-form-item">
            <label class="layui-form-label">设备名称：</label>
            <div class="layui-input-block">
                <input value="${device.deviceName}" type="text" name="deviceName" placeholder="请输入设备名称" lay-verify="required" autocomplete="off" class="layui-input">
            </div>
        </div>
    <#--所在教室（使用可搜索的下拉框）-->
        <div class="layui-form-item">
            <label class="layui-form-label">所在教室：</label>
            <div class="layui-input-block">
                <select name="deviceClassroom" lay-verify="" lay-search readonly>
                    <option value=""></option>
                    <#list classroomList as classroom>
                        <option value="${classroom.id}" <#if device.deviceClassroom?? && classroom.id == device.deviceClassroom>
                                selected </#if> >${classroom.roomBuilding} ${classroom.roomNumber}</option>
                    </#list>
                </select>

            </div>
        </div>

    <#--两个时间（生产时间、质保时间）-->
        <div class="layui-form-item">
            <label class="layui-form-label">生产时间：</label>
            <div class="layui-input-inline">
                <input type="text" name="deviceProductionDate" class="layui-input" id="device_PD" lay-verify="required" placeholder="请选择生产时间"
                       readonly>
            </div>
            <label class="layui-form-label">质保时间：</label>
            <div class="layui-input-inline">
                <input type="text" name="deviceServiceLife" class="layui-input" id="device_SL" lay-verify="required" placeholder="请选择质保截止时间"
                       readonly>
            </div>
        </div>
    <#--设备功能描述-->
        <div class="layui-form-item">
            <label class="layui-form-label">功能描述：</label>
            <div class="layui-input-block">
                <input value="${device.deviceFunction}" type="text" name="deviceFunction" placeholder="请输入设备功能" lay-verify="" autocomplete="off" class="layui-input">
            </div>
        </div>
    <#--设备采购商-->
        <div class="layui-form-item">
            <label class="layui-form-label">采购商：</label>
            <div class="layui-input-block">
                <input value="${device.deviceSource}" type="text" name="deviceSource" placeholder="请输入设备采购商" lay-verify="" autocomplete="off" class="layui-input">
            </div>
        </div>
    <#--备注-->
        <div class="layui-form-item  layui-form-text">
            <label class="layui-form-label">更多信息：</label>
            <div class="layui-input-block">
                <textarea name="deviceRemark" placeholder="关于此设备的更多信息，请在此输入..." class="layui-textarea" lay-verify=""
                          autocomplete="off">${device.deviceRemark}</textarea>
            </div>
        </div>
    <#--提交按钮-->
        <div class="layui-form-item">
            <button class="layui-btn" lay-submit="" lay-filter="add">立即复制</button>
        </div>
    </form>

</div>

<script src="${basePath}/js/jquery.js"></script>
<script src="${basePath}/plugins/kitadmin/layui.js"></script>
<script>
    layui.use(['laydate', 'form'], function () {
        var form_device_update = layui.form;
        var device_PD_copy = layui.laydate;
        var date_SL_copy = layui.laydate;

        //执行一个laydate实例
        device_PD_copy.render({
            elem: '#device_PD', //指定元素
            trigger: 'click',
            value: '${device.deviceProductionDate?string('yyyy-MM-dd')}'

        });
        date_SL_copy.render({
            elem: '#device_SL', //指定元素
            trigger: 'click',
            value: '${device.deviceServiceLife?string('yyyy-MM-dd')}'
        });

        // 监听提交，发送请求
        form_device_update.on('submit(add)', function (data) {
            $.post("add", data.field, function (data) {
                if (data.status === 200) {
                    // 弹窗确认下一步操作
                    layer.open({
                        title: "设备信息复制成功！",
                        type: 0,
                        btn: ["继续复制", "关闭"],
                        area: ['200px', '160px'],
                        content: '是否继续复制？',
                        // 弹出层弹出后回调
                        success: function () {
                        },
                        // 点击第一个按钮的响应事件
                        btn1: function (index) {
                            // 关闭弹窗
                            layer.close(index);
                        },
                        // 点击第二个按钮的响应事件
                        btn2: function (index) {
                            // 关闭弹窗
                            layer.close(index);
                            // 先得到当前iframe层的索引
                            var index2 = parent.layer.getFrameIndex(window.name);
                            // 关闭当前弹窗
                            parent.layer.close(index2);
                        }
                    });
                    // layer.alert("设备信息复制成功！", {offset: 't', icon: 1}, function (index) {
                    //     layer.close(index);
                    //     var index2 = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    //     parent.layer.close(index2);
                    // });
                }
                else{
                    layer.alert(data.message, {offset: 't', icon: 2});
                }
            });
            return false;
        });
    });

</script>


</body>
</html>